package com.imooc.mall.utils;

import com.imooc.mall.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author zwj
 * @Description: MD5工具类
 * @date 2022/10/17 4:20 下午
 */
public class MD5Utils {
    public static String getMD5Str(String strValue) throws NoSuchAlgorithmException {
        //获取md5
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        //Base64转码
        String string = Base64.encodeBase64String(md5.digest((strValue + Constant.SALT).getBytes()));
        return string;
    }

    public static void main(String[] args) {
        String md5 = "1234";
        try {
            md5 = getMD5Str(md5);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        System.out.println(md5);
    }
}
